<template>
  <a-modal title="推优" :visible="visible" @cancel="cancel" width="900px">
    <a-form-model ref="ruleForm" :model="form" :rules="rules" :label-col="{ span: 6 }" :wrapper-col="{ span: 18 }">
      <custom-form :is-emit="false" :form-list="formList" :form="form" :edit-model="''"></custom-form>
    </a-form-model>
    <template slot="footer">
      <a-button @click="cancel"> 取消 </a-button>
      <a-button type="primary" @click="submit" v-loading="loading"> 提交 </a-button>
    </template>
  </a-modal>
</template>
<script>
import { pushProgramGood } from '@/api/technical/approval'
export default {
  props: {
    // 显隐控件
    visible: {
      type: Boolean,
      default() {
        return false
      }
    },
    excellenceId:{
      type: String,
      default() {
        return '';
      }
    }
  },
  data() {
    return {
      form: {
        fileInfoVOS:[],
      },
      loading:false,
      rules: {
        content: [{ required: true, message: '请输入' }],
        //fileInfoVOS: [{ required: true, message: '请附件上传' }]
      }
    }
  },
  computed: {
    formList() {
      return [
        {
          keyName: 'content',
          type: 'BaseTextarea',
          label: '推优理由',
          span: 24
        },
        {
          keyName: 'fileInfoVOS',
          type: 'uploadFile',
          label: '附件上传',
          span: 24,
          businessCode: 'TM06',
          hiddenRemark: true,
          remark:'备注：上传相关证明和支撑文件',
        }
      ]
    }
  },
  methods: {
    cancel() {
      this.$emit('cancel', false)
    },
    validateForm() {
      let flag = false
      this.$refs.ruleForm.validate((e) => {
        if (e) {
          flag = true
        } else {
          this.$message.warning('请填写完所有必填项信息')
        }
      })
      return flag
    },
    submit() {
      if (!this.validateForm()) {
        return
      }
      if(this.form.fileInfoVOS.length == 0){
        this.$message.warning('请上传附件')
        return
      }
      let parms = {
        auditStatus: 'DRAFT',
        constructionProgramId:this.excellenceId
      }
      let req = {...parms,...this.form};
      this.loading = true;
      pushProgramGood(req).then((res)=>{
        if(res.data.code == '200'){
          this.loading = false;
          this.$message.success('推优成功');
          this.$emit('cancel',true)
        }
        this.$refs.ruleForm.resetFields();
      })
    }
  }
}
</script>